<?php

/**
 * This is the model class for table "establishments".
 *
 * The followings are the available columns in table 'establishments':
 * @property integer $Id
 * @property string $Name
 * @property integer $EstablishmentType_Id
 *
 * The followings are the available model relations:
 * @property Buildingconstruction[] $buildingconstructions
 * @property Establishmenttypes $establishmentType
 * @property Generalinfo[] $generalinfos
 * @property Sectionaloccupancy[] $sectionaloccupancies
 */
class Establishments extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'establishments';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('EstablishmentType_Id', 'numerical', 'integerOnly'=>true),
			array('Name', 'length', 'max'=>45),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('Id, Name, EstablishmentType_Id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'buildingconstruction' => array(self::HAS_ONE, 'Buildingconstruction', 'Establishment_Id'),
			'establishmentType' => array(self::BELONGS_TO, 'Establishmenttypes', 'EstablishmentType_Id'),
			'exitdetail'=> array(self::HAS_ONE, 'Exitdetails', 'Establishment_id'),
			'meansofegress'=> array(self::HAS_ONE, 'Meansofegress', 'Establishment_id'),
			'generalinformation' => array(self::HAS_ONE, 'Generalinformation', 'Establishment_id'),
			'sectionaloccupancy' => array(self::HAS_ONE, 'Sectionaloccupancy', 'Establishment_Id'),
			//kace
			'alarmsystem' => array(self::HAS_ONE, 'Alarmsystem', 'Establishment_Id'),
			'areaofsaferefuge' => array(self::HAS_ONE, 'Areaofsaferefuge', 'Establishment_Id'),
			'automaticfiresuppression' => array(self::HAS_ONE, 'Automaticfiresuppression', 'Establishment_Id'),
			'buildingserviceequipment' => array(self::HAS_ONE, 'Buildingserviceequipment', 'Establishment_Id'),
			'emergencylight' => array(self::HAS_ONE, 'Emergencylights', 'Establishment_Id'),
			'exitsign' => array(self::HAS_ONE, 'Exitsigns', 'Establishment_Id'),
			'firewall' => array(self::HAS_ONE, 'Firewall', 'Establishment_Id'),
			'firstaidfireprotection' => array(self::HAS_ONE, 'Ffirstaidfireprotection', 'Establishment_Id'),
			'hazardousarea' => array(self::HAS_ONE, 'Hazardousareas', 'Establishment_Id'),
			//fern
			'horizontalexit' => array(self::HAS_ONE, 'Horizontalexits', 'Establishment_Id'),
			'operatingfeature' => array(self::HAS_ONE, 'Operatingfeatures', 'Establishment_Id'),
			'othersafetyfeature' => array(self::HAS_ONE, 'Othersafetyfeatures', 'Establishment_Id'),
			'protectionofverticalopening' => array(self::HAS_ONE, 'Protectionofverticalopenings', 'Establishment_Id'),
			'ramp' => array(self::HAS_ONE, 'Ramps', 'Establishment_Id'),
			'standpipe' => array(self::HAS_ONE, 'Standpipe', 'Establishment_Id'),
			'verticalexit' => array(self::HAS_ONE, 'Verticalexits', 'Establishment_Id'),
			'warningsafetysign' => array(self::HAS_ONE, 'Warningsafetysigns', 'Establishment_Id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'Id' => 'ID',
			'Name' => 'Name',
			'EstablishmentType_Id' => 'Establishment Type',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('Id',$this->Id);
		$criteria->compare('Name',$this->Name,true);
		$criteria->compare('EstablishmentType_Id',$this->EstablishmentType_Id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Establishments the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
